package com.bawei.mvp.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.bawei.mvp.http.bean.ErrorBean;
import com.bawei.mvp.presenter.IPresenter;
import com.blankj.utilcode.util.ToastUtils;

import org.greenrobot.eventbus.EventBus;


public abstract class BaseActivity<P extends IPresenter> extends AppCompatActivity implements IActivity, IView, View.OnClickListener {

    protected P mPresenter;
    //页码容器
    protected LinearLayout baseLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseLayout = new LinearLayout(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        baseLayout.setLayoutParams(params);
        baseLayout.setOrientation(LinearLayout.VERTICAL);
        baseLayout.addView(LayoutInflater.from(this).inflate(bandLayout(), baseLayout,false));

        setContentView(baseLayout);
        initView();
        initData();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showToast(String msg) {
        ToastUtils.showShort(msg);
    }

    @Override
    public void showAlert() {

    }

    @Override
    public void onClick(View v) {
        //处理连续点击
    }



    @Override
    public void hideErrorView() {

    }

    public void goAct(Class<?> cls) {
        startActivity(new Intent(this, cls));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)){
            EventBus.getDefault().unregister(this);
        }
        if (mPresenter != null) {
            mPresenter.destroy();
            mPresenter = null;
        }
    }
}
